﻿using System.Collections.Generic;
#if TASKSUPPORT
using System.Threading.Tasks;
#endif
using System.Collections.Specialized;
using JetBrains.Annotations;
using MugenMvvmToolkit.Models;

namespace MugenMvvmToolkit.Interfaces.ViewModels
{
    /// <summary>
    ///     Represents the view-model that can contains a collection of other <see cref="IViewModel" />.
    /// </summary>
    public interface IMultiViewModel : IViewModel, INotifyCollectionChanged
    {
        /// <summary>
        ///     Gets or sets the selected view-model.
        /// </summary>
        IViewModel SelectedItem { get; set; }

        /// <summary>
        ///     Gets the collection of <see cref="IViewModel" />s.
        /// </summary>
        [NotNull]
        IList<IViewModel> ItemsSource { get; }

        /// <summary>
        ///     Gets or sets the value. If <c>true</c> the view-model will disposed child view models when it closed.
        /// </summary>
        bool DisposeViewModelOnRemove { get; set; }

        /// <summary>
        ///     Gets or sets the value. If <c>true</c> the view-model will disposed child view models when it will disposed.
        /// </summary>
        bool DisposeViewModelsOnDispose { get; set; }

        /// <summary>
        ///     Adds the specified <see cref="IViewModel" /> to <see cref="ItemsSource" />.
        /// </summary>
        /// <param name="viewModel">
        ///     The specified <see cref="IViewModel" />.
        /// </param>
        void AddViewModel([NotNull]IViewModel viewModel);

#if TASKSUPPORT
        /// <summary>
        ///     Removes the specified <see cref="IViewModel" /> from <see cref="ItemsSource" />.
        /// </summary>
        /// <param name="viewModel">
        ///     The specified <see cref="IViewModel" />.
        /// </param>
        /// <param name="parameter">The specified parameter, if any.</param>        
        Task<bool> RemoveViewModel([NotNull]IViewModel viewModel, object parameter = null);
#else
        /// <summary>
        ///     Removes the specified <see cref="IViewModel" /> from <see cref="ItemsSource" />.
        /// </summary>
        /// <param name="viewModel">
        ///     The specified <see cref="IViewModel" />.
        /// </param>
        /// <param name="parameter">The specified parameter, if any.</param>        
        IOperationResult<bool> RemoveViewModel([NotNull]IViewModel viewModel, object parameter = null);
#endif
        /// <summary>
        ///     Clears all view models from <see cref="ItemsSource" />.
        /// </summary>
        /// <param name="isDisposeViewModel">Indicating that need dispose view models.</param>
        void Clear(bool isDisposeViewModel);

        /// <summary>
        ///     Occurs when the <c>SelectedItem</c> property changed.
        /// </summary>
        event SelectedItemChangedHandler<IViewModel> SelectedItemChanged;
    }
}